<template>
  <div class="sign" id="app">

    <div class="logo"></div>
    <div class="main">
      <h4 class="title">
        <div class="normal-title">
          <a class="active" href="#">登录</a>
          <b>·</b>
          <a id="js-sign-up-btn" class href="/registerPage">注册</a>
        </div>
      </h4>
      <div class="js-sign-in-container">
        <form id="new_session" accept-charset="UTF-8">
          <input name="utf8" type="hidden" value="&#x2713;" />
          <input
            type="hidden"
            name="authenticity_token"
            value="VJhEt/f73yYHt7fqhqphrVypOthfDVBOkTv95R9T69efti2m8sPtreA6eP8bbUcxpi4B3Pq4jK5gq/u+xnuxnA=="
          />

          <!-- 正常登录登录名输入框 -->
          <div class="input-prepend restyle js-normal">
            <input
              placeholder="手机号或邮箱"
              type="text"
              v-model="username"
              id="session_email_or_mobile_number"
            />
            <i class="iconfont ic-user"></i>
          </div>
          <br />
          <div class="input-prepend">
            <input
              placeholder="密码"
              type="password"
              id="session_password"
              v-model="password"
            />
            <i class="iconfont ic-password"></i>
          </div>
          <input
            value="false"
            type="hidden"
            name="session[oversea]"
            id="session_oversea"
          />
          <div>
            <input
              id="sign-in-form-captcha-challenge"
              name="captcha[validation][challenge]"
              autocomplete="off"
              type="hidden"
            />
            <input
              id="sign-in-form-captcha-gt"
              name="captcha[validation][gt]"
              autocomplete="off"
              type="hidden"
            />
            <input
              id="sign-in-form-captcha-validate"
              name="captcha[validation][validate]"
              autocomplete="off"
              type="hidden"
            />
            <input
              id="sign-in-form-captcha-seccode"
              name="captcha[validation][seccode]"
              autocomplete="off"
              type="hidden"
            />
          </div>
          <br />
          <button
            class="sign-in-button"
            @click="login()"
          >
            <span id="sign-in-loading"></span>
            登录
          </button>
        </form>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      logoUrl: "./static/images/logo.png",
      username: "",
      password: "",
    };
  },
  methods: {
    // login:function(){},
    login() {
      if (this.username == "" || this.password == "") {
        alert("用户名或者密码不能为空！");
        return false;
      } else {
        this.$axios({
          method: "POST",
          url: "api/to_index",
          //    post使用的传值方法
          data: {
            username: this.username,
            password: this.password,
          },
        }).then(res=>{
              this.username = res.data.user_name
              // alert(session.getAttribute("username"));
              //    console.log(data);
              this.$session.set("username",res.data.user_name);
              this.$session.set("userid",res.data.user_id);
              location.href = res.data.url+'?username='+this.username;
            }
          ).catch(
            //    后台登录失败打印错误
            (e) => {
              alert('登录失败！')
              console.log(e);
            }
          );
        // console.log(this.username,this.password);
      }
    },
  },
};
</script>
<style  scoped>
</style>